﻿using MODEL;
using SysHelper;
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SysController
{
    public static partial class ProductController
    {
        //    public static int UploadProductImage(List<ProductImageDH> list)
        //    {
        //        foreach (var item in list)
        //        {
        //            OperateContext.CurrentContext.BllSession.IProductImageDH_BLL.ModifyIsNullADD(item, p => p.Code == item.Code && p.l_localfilename == item.l_localfilename && p.IsDel == false, true);
        //        }
        //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductImageDH).Name);

        //    }

        //    //public static List<PuTable> UploadProduct(string[] codelist)
        //    //{
        //    //    return null;// OperateContext.CurrentContext.BllSession.IPuTable_BLL.GetListByWhere(s => codelist.Contains(s.code));
        //    //}

        //    //public static PuTable UploadProduct(string code)
        //    //{
        //    //    return OperateContext.CurrentContext.BllSession.IPuTable_BLL.GetListByWhere(s => code == s.code).FirstOrDefault();
        //    //}

        //    public static ProductImageDH ProductImg(string code)
        //    {
        //        return OperateContext.CurrentContext.BllSession.IProductImageDH_BLL.GetListByWhere(s => s.Code == code).FirstOrDefault();
        //    }

        //    public static int SetProductCategoryAttrVal(List<ProductCategoryAttrVal> list)
        //    {
        //        foreach (var model in list)
        //        {
        //            OperateContext.CurrentContext.BllSession.IProductCategoryAttrVal_BLL.ModifyIsNullADD(model, s => s.Code == model.Code && s.attrId == model.attrId && s.catePubId == model.catePubId, true);
        //        }
        //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductCategoryAttrVal).Name);
        //    }

        //    //public static int ModifyProductInfo(ProductInfo info)
        //    //{
        //    //    if (info != null)
        //    //    {
        //    //        OperateContext.CurrentContext.BllSession.IProductInfo_BLL.Modify(info, s => s.Code == info.Code && s.IsDel == false, "catePubId", "pubNameCn", "groupId", "ProductNameEN", "ProductDescEN", "ProductPackageEN", "Height", "Length", "Width", "Weight", "Lots", "PackingQuantity", "MeasureCode", "ProductPrice", "ShippingTemplate", "supplierId");
        //    //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductInfo).Name);
        //    //    }
        //    //    else
        //    //    {
        //    //        return -1;
        //    //    }
        //    //}

        //    //public static int ModifyProductInfo(ProductInfo info,int i)
        //    //{
        //    //    OperateContext.CurrentContext.BllSession.IProductInfo_BLL.Modify(info, s => s.Code == info.Code && s.AccountName == info.AccountName && s.catePubId == info.catePubId, "itemcode", "productId");
        //    //    return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductInfo).Name);
        //    //}

        //    //public static List<ProductInfo> QueryProduct(string AccountName)
        //    //{
        //    //    return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.GetListByWhere(s => s.IsUpload == true && s.IsDel == false && s.OperationType == "1" && s.AccountName == AccountName);
        //    //}

        //    //public static List<ProductInfo> QueryProduct(string AccountName, string[] CodeArr)
        //    //{
        //    //    if (CodeArr == null)
        //    //        return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.GetListByWhere(s => s.IsDel == false && s.AccountName == AccountName);
        //    //    else
        //    //        return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.GetListByWhere(s => CodeArr.Contains(s.Code) && s.IsDel == false && s.AccountName == AccountName);
        //    //}

        //    public static List<ProductImageDH> QueryImage(ProductInfo model)
        //    {
        //        return OperateContext.CurrentContext.BllSession.IProductImageDH_BLL.GetListByWhere(s => s.Code == model.Code && s.IsDel == false);
        //    }

        //    public static List<ProductPackageInfo> QueryProductPackageInfo(ProductInfo model)
        //    {
        //        return OperateContext.CurrentContext.BllSession.IProductPackageInfo_BLL.GetListByWhere(s => s.Code == model.Code && s.IsDel == false);
        //    }

        //    public static List<ProductCategoryAttrVal> QueryProductCategoryAttrVal(ProductInfo model)
        //    {
        //        return OperateContext.CurrentContext.BllSession.IProductCategoryAttrVal_BLL.GetListByWhere(s => s.Code == model.Code && s.IsDel == false);
        //    }

        //    public static List<ProductPicture> QueryUploadPicture(string[] codeArr)
        //    {
        //        return OperateContext.CurrentContext.BllSession.IProductPicture_BLL.GetListByWhere(s => s.IsDel == false && codeArr.Contains(s.Code));
        //    }
        //}

        //public static partial class ProductController
        //{
        //    public static List<ProductTranslation> QueryProductTranslation(string[] codeArr)
        //    {
        //        return OperateContext.CurrentContext.BllSession.IProductTranslation_BLL.GetListByWhere(s => s.IsDel == false && codeArr.Contains(s.Code));
        //    }

        //    public static List<ProductInfo> QueryProductInfo(int ProductStatusId, int CategoryID, string[] CodeArr)
        //    {
        //        if (CodeArr != null)
        //            return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.GetListByWhere(s => s.IsDel == false && s.ProductStatusID == ProductStatusId && CodeArr.Contains(s.Code));
        //        return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.GetListByWhere(s => s.IsDel == false && s.ProductStatusID == ProductStatusId);
        //    }

        //    public static List<UP_GetProductInfos_Result> QueryProductInfo(string code, Nullable<int> categoryID, Nullable<int> productStatusID, Nullable<bool> isLock, Nullable<bool> isDel)
        //    {
        //        var codeParameter = code != null ?
        //           new ObjectParameter("Code", code) :
        //           new ObjectParameter("Code", typeof(string));

        //        var categoryIDParameter = categoryID.HasValue ?
        //            new ObjectParameter("CategoryID", categoryID) :
        //            new ObjectParameter("CategoryID", typeof(int));

        //        var productStatusIDParameter = productStatusID.HasValue ?
        //            new ObjectParameter("ProductStatusID", productStatusID) :
        //            new ObjectParameter("ProductStatusID", typeof(int));

        //        var isLockParameter = isLock.HasValue ?
        //            new ObjectParameter("IsLock", isLock) :
        //            new ObjectParameter("IsLock", typeof(bool));

        //        var isDelParameter = isDel.HasValue ?
        //            new ObjectParameter("IsDel", isDel) :
        //            new ObjectParameter("IsDel", typeof(bool));
        //        return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.ExecProcedure<UP_GetProductInfos_Result>("UP_GetProductInfos", codeParameter, categoryIDParameter, productStatusIDParameter, isLockParameter, isDelParameter);
        //    }

        //    public static List<UP_GetProductInfo_SetSpecifics_Result> QueryProudctInfoSetSpecifics(string code, Nullable<int> salesPlatformSiteInfoID, Nullable<int> salesPlatformSiteInfoCategoryID, Nullable<int> productStatusId, Nullable<int> languageTypeID)
        //    {
        //        var codeParameter = code != null ?
        //            new ObjectParameter("Code", code) :
        //            new ObjectParameter("Code", "");

        //        var salesPlatformSiteInfoIDParameter = salesPlatformSiteInfoID.HasValue ?
        //            new ObjectParameter("SalesPlatformSiteInfoID", salesPlatformSiteInfoID) :
        //            new ObjectParameter("SalesPlatformSiteInfoID", typeof(int));

        //        var salesPlatformSiteInfoCategoryIDParameter = salesPlatformSiteInfoCategoryID.HasValue ?
        //            new ObjectParameter("SalesPlatformSiteInfoCategoryID", salesPlatformSiteInfoCategoryID) :
        //            new ObjectParameter("SalesPlatformSiteInfoCategoryID", typeof(int));

        //        var productStatusIdParameter = productStatusId.HasValue ?
        //            new ObjectParameter("ProductStatusId", productStatusId) :
        //            new ObjectParameter("ProductStatusId", typeof(int));

        //        var languageTypeIDParameter = languageTypeID.HasValue ?
        //            new ObjectParameter("LanguageTypeID", languageTypeID) :
        //            new ObjectParameter("LanguageTypeID", typeof(int));

        //        return OperateContext.CurrentContext.BllSession.IProductAd_BLL.ExecProcedure<UP_GetProductInfo_SetSpecifics_Result>("UP_GetProductInfo_SetSpecifics", codeParameter, salesPlatformSiteInfoIDParameter, salesPlatformSiteInfoCategoryIDParameter, productStatusIdParameter, languageTypeIDParameter);

        //    }
        //}



        //public static partial class ProductController
        //{
        //    public static int ModifyProductInfo(ProductInfo model, params string[] Prop)
        //    {
        //        OperateContext.CurrentContext.BllSession.IProductInfo_BLL.Modify(model, s => s.Code == model.Code, Prop);
        //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductInfo).Name);
        //    }

        //}



        //public static partial class ProductController
        //{
        //    public static int AddProductTranslation(ProductTranslation model, string code, int languageType)
        //    {
        //        OperateContext.CurrentContext.BllSession.IProductTranslation_BLL.ModifyIsNullADD(model, s => s.Code == code && s.LanguageTypeID == languageType && s.IsLock == false, true);
        //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductTranslation).Name);
        //    }

        //    public static int AddProductAd(List<ProductAd> list)
        //    {
        //        foreach (var item in list)
        //        {
        //            OperateContext.CurrentContext.BllSession.IProductAd_BLL.ModifyIsNullADD(item, s => s.IsDel == false
        //                && s.Code == item.Code
        //                && s.SalesPlatformSiteInfoCategoryID == item.SalesPlatformSiteInfoCategoryID
        //                && s.SalesPlatformSiteInfoID == item.SalesPlatformSiteInfoID);
        //        }
        //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductAd).Name);
        //    }

        //    public static int AddProductSpecifics(List<ProductSpecifics_DHgate> list)
        //    {
        //        foreach (var item in list)
        //        {
        //            OperateContext.CurrentContext.BllSession.IProductSpecifics_DHgate_BLL.ModifyIsNullADD(item, s => s.IsDel == false 
        //                && s.Code == item.Code && s.SalesPlatformSiteInfoCategoryID == item.SalesPlatformSiteInfoCategoryID 
        //                && s.SalesPlatformSiteInfoID == item.SalesPlatformSiteInfoID && s.SpecificsName == item.SpecificsName 
        //                && s.SpecificsValue == item.SpecificsValue, true);
        //        }
        //        return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductSpecifics_DHgate).Name);
        //    }

        public static List<ProductInfo> QueryProductInfo()
        {
            return OperateContext.CurrentContext.BllSession.IProductInfo_BLL.GetListByWhere(s => s.IsDel == false);
        }

        public static int SaveProductInfo(ProductInfo model)
        {
            OperateContext.CurrentContext.BllSession.IProductInfo_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductInfo).Name);
        }
    } 
}
